package com.ziyun.pop.mall.module.user.web;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.service.ucenter.api.UserAccessoryService;
import com.service.ucenter.model.accessory.UserAccessoryParamDto;
import com.service.ucenter.model.accessory.UserAccessoryResultDto;
import com.service.utils.push.umeng.JsonResult;
import com.utility.JsonUtils;
import com.ziyun.pop.mall.system.config.HttpRequestLocal;

/**
 * 用户附件
 * 
 * @author lvai
 * @date 2018年9月6日 下午2:07:23
 */
@Controller
public class UserAccessoryController {
	private static Logger _log = LoggerFactory.getLogger(UserAccessoryController.class);
	private static final String MODEL = "/user/userAccessory";

	@Autowired
	private UserAccessoryService userAccessoryService;

	@Autowired
	private HttpRequestLocal httpRequestLocal;

	/**
	 * 添加附件
	 * 
	 * @return
	 */
	@PostMapping(MODEL + "/addAccessory.json")
	@ResponseBody
	public JsonResult<Map<String, Object>> addAccessory(HttpServletRequest request, HttpServletResponse response) {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		String requestData = request.getParameter("requestData");
		UserAccessoryParamDto userAccessoryParamDto = JsonUtils.string2Object(requestData, UserAccessoryParamDto.class);
		List<UserAccessoryParamDto> userAccessoryParamDtos = new ArrayList<UserAccessoryParamDto>();
		userAccessoryParamDtos.add(userAccessoryParamDto);
		Map<String, List<UserAccessoryParamDto>> map = new HashMap<String, List<UserAccessoryParamDto>>();
		map.put("filesList", userAccessoryParamDtos);
		Long userId = (Long) httpRequestLocal.getSessionValue("userId");
		List<UserAccessoryResultDto> resultDtos = userAccessoryService.addAccessory(map).getData();
		resultMap.put("resultDtos", resultDtos);
		return JsonResult.success(resultMap);
	}

}
